package com.linkage.service.background;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.linkage.pojo.order.SingleOrder;
import com.linkage.repository.background.OrderManageRepository;
import com.linkage.repository.order.OrderRepository;


/**
 * @标题：订单后台管理业务
 * @描述：订单业务操作
 * @author: 邓达
 */

@Service
public class OrderManageService {

	@Autowired
	private OrderManageRepository orderManageRepository;
	
	
	//列出所有所选订单状态的订单,并根据订单状态排序
	//0 表示显示全部
		public  List<SingleOrder> listOrders(@Param("status") Integer status){
			return this.orderManageRepository.listOrders(status);
			
		}
	
		//列出所选订单信息
		public  Map<String, Object>  getOrderDetailById(Integer singleOrderId){
			return this.orderManageRepository.getOrderDetailById(singleOrderId);
			
		}
		
		/*更改订单状态订单状态：
	    	1.	待付款
	    	2.	已付款
	    	3.	配货中
	    	4.	待发货
	    	5.	已发货
	    	6.	已收货
	    	7.	已取消
	    	*/
		public void changeOrderStatus(@Param("statusId")Integer statusId,@Param("singleOrderId") Integer singleOrderId){
			if(statusId >0 && statusId < 8 && this.orderManageRepository.getOrderById(singleOrderId) != null ){
			    this.orderManageRepository.changeOrderStatus(statusId,singleOrderId);
			}
		    
		}
		
		public SingleOrder getOrderById(@Param("singleOrderId")Integer singleOrderId){
		    return this.orderManageRepository.getOrderById(singleOrderId);
		}
		
		
	    public List<Map<String, Object>> listAllOrderDetails(){
	        return this.orderManageRepository.listAllOrderDetails();
	    }
	    
	    public List<Map<String, Object>> listOrderByStatus(Integer status){
	        return this.orderManageRepository.listOrderByStatus(status);
	    }
	    
}
